<?php 
/**************************************************/
## Class Name - Model_Forums (Contains all the functions related Forum modules)
## Created By - Techmodi (22/08/2011)
/**************************************************/
class Model_Forums extends Database
{	
	function Model_Forums() {	
		$this->Forums = FORUMS;
		$this->ForumsComment = FORUMSCOMMENT;
		$this->Database();
	}
	
	// for add Forum
	function addForums($array) {
		$this->InsertData($this->Forums, $array);
		return mysql_insert_id();
	}
	
	## List all Forums
	function getAllForums($search,$limit='',$offset='') {
		$fields = array();	
		$tables = array($this->Forums);
		if(trim($search)) {
			$where[] = "title LIKE '%".$search."%'";
		}
		$result1 = $this->SelectData($fields,$tables, $where , $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get Forum details by id
	function getForumsDetailsById($id) {
		$fields = array();	
		$tables = array($this->Forums);
		$result1 = $this->SelectData($fields,$tables, $where= array("id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit Forum by id
	function editForumById($array, $Id){
		$this->UpdateData($this->Forums,$array,"id",$Id,0);
	}
	
	## Update Forum status with multiple ids
	function updateForumstatus($ids, $status) {
		$sql = "UPDATE ".$this->Forums." SET status='".$status."' WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete Forum with multiple ids
	function deleteForum($ids, $status) {
		$sql = "DELETE FROM ".$this->Forums." WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete Forum  by id
	function deleteForumById($id){
		$this->DeleteData($this->Forums,"id",$id);
	}
	
	/*****************  Forum Comment Start   ***********************************/
	
	// for add Forum Comment
	function addForumComment($array) {
		$this->InsertData($this->ForumsComment, $array);
		return mysql_insert_id();
	}
	
	## Get Forum Comment by Forum id
	function getAllForumsComment($forum_id,$search,$limit='',$offset='') {
		$fields = array();	
		$tables = array($this->ForumsComment);
		if(trim($search)) {
			$where[] = "comment LIKE '%".$search."%' and forum_id=$forum_id";
		}
		else
		{
			$where[] = "forum_id=$forum_id";
		}
		$result1 = $this->SelectData($fields,$tables, $where , $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get Forum Comment details by id
	function getForumCommentDetailsById($id) {
		$fields = array();	
		$tables = array($this->ForumsComment);
		$result1 = $this->SelectData($fields,$tables, $where= array("id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit Forum Comment by id
	function editForumCommentById($array, $Id){
		$this->UpdateData($this->ForumsComment,$array,"id",$Id,0);
	}
	
	## Update Forum  Comment status with multiple ids
	function updateForumCommentStatus($ids, $status) {
		$sql = "UPDATE ".$this->ForumsComment." SET status='".$status."' WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete Forum Comment with multiple ids
	function deleteForumComment($ids, $status) {
		$sql = "DELETE FROM ".$this->ForumsComment." WHERE id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete Forum Comment by id
	function deleteForumCommentById($id){
		$this->DeleteData($this->ForumsComment,"id",$id);
	}
	
	## Get Forum Comment by Forum id
	function getCommentCountByForumId($id) {
		$fields = array('count(*) as cnt');	
		$tables = array($this->ForumsComment);
		$result1 = $this->SelectData($fields,$tables, $where= array("forum_id=$id"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result['cnt'];
	}

    
 
}
?>


